package cc;

import java.util.Arrays;
import java.util.Scanner;

interface IntegerStack {
	public Integer push(Integer item);//如果item为null，则不入栈直接返回null。如果栈满，也返回null。如果插入成功，返回item。
	public Integer pop(); //出栈，如果为空，则返回null。出栈时只移动栈顶指针，相应位置不置为null
	public Integer peek(); //获得栈顶元素，如果为空，则返回null.
	public boolean empty(); //如果为空返回true
	public int size(); //返回栈中元素个数
}


class ArrayIntegerStack implements IntegerStack {
		
	private Integer[] stack;
	private int top;
	
	public ArrayIntegerStack(int n){
		this.stack = new Integer[n];
}	
	
	public Integer push(Integer item) {
	
		if(item == null)
		return null;
		if(top == stack.length)
			return null;
		stack[top++]= item;
		return item;
	}

	
	public Integer pop() {
		
		if(this.empty())
		return null;
		top--;
		return stack[top];
	}

	
	public Integer peek() {
		
		if(this.empty())
			return null;
		return stack[top-1];
	}

	
	public boolean empty() {
		
		if(top == 0)
			return true;
		return false;
		
	}

	
	public int size() {		
		return top;
	}
	
	public Integer[] getStack() {
		
		return stack;
	}
	
}
	



public class Main {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		ArrayIntegerStack Stack = new ArrayIntegerStack(n);
		int m = sc.nextInt();
		for (int i= 0; i< m ;i++) {
				Integer num = sc.nextInt();
				System.out.println(Stack.push(num));
		}
		System.out.print(Stack.peek()+","+Stack.empty()+","+Stack.size()+"\n");
		System.out.println(Arrays.toString(Stack.getStack()));
		int x = sc.nextInt();
		for (int j= 0; j < x; j++) {
			System.out.println(Stack.pop());
		}
		System.out.print(Stack.peek()+","+Stack.empty()+","+Stack.size()+"\n");
		System.out.println(Arrays.toString(Stack.getStack()));
		
	}


}
